home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BT_LOW2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.7 KB  |  62 lines

  1. /*  bt_low2.c - low level functions for BTREE module */
  2. #include   "stdio.h"
  3. #include   "btree.h"
  4. #include   "bt_macro.h"
  5.  
  6. extern    IX_DESC  *pci ;
  7.  
  8. int  prev_entry(pb,off)         /* back up one entry */
  9.   BLOCK *pb ;
  10.   int    off ;
  11.   {
  12.      if( off <= 0 )            /* at start of block ? */
  13.     return( -1 ) ;            /* yes - can't back up */
  14.      off = scan_blk(pb,off) ;        /* find previous entry */
  15.      return( off ) ;
  16.   }
  17.  
  18. int  next_entry(pb,off)         /* go forward one entry */
  19.   BLOCK *pb ;
  20.   int    off ;
  21.   {
  22.      if( off >= pb->bend )        /* at end of block ? */
  23.     return( -1 ) ;            /* yes - can't go forward */
  24.      off = off + ENT_SIZE(ENT_ADR(pb,off)) ;    /* move past entry */
  25.      if( off >= pb->bend )        /* at end of block ? */
  26.     return( -1 ) ;            /* yes - no entry here */
  27.      return( off ) ;
  28.   }
  29.  
  30. int  copy_entry(to,from)        /* copy an entry */
  31.   ENTRY *to ;                /* to this address */
  32.   ENTRY *from ;             /* from this address */
  33.   {
  34.      int   ne ;
  35.  
  36.      ne = ENT_SIZE(from) ;        /* get the entry's size */
  37.      mover(to,from,ne) ;        /* move that many bytes */
  38.   }
  39.  
  40. int  scan_blk(pb,n)            /* find offset of last entry */
  41.   BLOCK *pb ;                /* in this block */
  42.   int    n ;                /* starting before this position */
  43.   {
  44.      int   i  , last ;
  45.  
  46.      i = 0 ; last = 0 ;
  47.      while( i < n )            /* repeat until position reached */
  48.     {  last = i ;            /* save where we are now */
  49.        i = i + ENT_SIZE( ENT_ADR(pb,i) ) ;    /* move past entry */
  50.     }
  51.      return( last ) ;            /* return last offset < n */
  52.   }
  53.  
  54. int  last_entry(pb)            /* find last entry in a block */
  55.   BLOCK *pb ;                /* the block */
  56.   {
  57.                     /* scan for offset of last entry */
  58.      return( scan_blk(pb,pb->bend) ) ;    /* and return the offset */
  59.   }
  60.  
  61.  
  62.